package com.swak.incrementer;

import com.swak.utils.RegexUtil;

/**
 * 创建分布式 ID 生成器；
 * 
 * @author 618lf
 */
public class DistributeIdGenerator implements IdGenerator {

	private final Long64Generator idgen;

	public DistributeIdGenerator(String sn) {
		String[] ls = RegexUtil.newRegexpMatcher("([^-]+)-([\\d]+)-([\\d]+)").getArrayGroups(sn);
		idgen = new Long64Generator(Integer.parseInt(ls[2]), Integer.parseInt(ls[3]));
	}

	@Override
	@SuppressWarnings("unchecked")
	public Long id() {
		return idgen.id();
	}
}
